
package net.qiqbframework.messaging.annotation;


import net.qiqbframework.messaging.BatchMessage;
import net.qiqbframework.messaging.Message;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;


public class CollectionPayloadParameterResolver implements HandlerParameterResolver<Collection<Object>> {
    /**
     * 集合内的元素类型
     */
    private final Class<?> payloadType;

    public CollectionPayloadParameterResolver(Class<?> payloadType) {
        this.payloadType = payloadType;
    }

    @Override
    public Collection<Object> resolveParameter(Message<?> message) {

        if (message instanceof BatchMessage<?> batchMessage){

            final List list = batchMessage.getPayload().stream().map(Message::getPayload).toList();
            return list;
        }
        return null;
    }

    @Override
    public boolean support(Message message) {

        return message instanceof BatchMessage<?>;
    }

    @Override
    public Class<?> supportedPayloadType() {
        return Collection.class;
    }
}
